package com.ngovanhau.justsort.adapter;

import java.util.ArrayList;
import java.util.List;

import com.ngovanhau.justsort.model.Level;
import com.ngovanhau.justsort.model.LevelSetting;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;


public class LevelAdapter extends BaseAdapter {
	
	Context context;
	List<Level> list;
	final List<Row> rows;

	public LevelAdapter(Context context, List<Level> list) {
		this.context = (Activity) context;
		this.list = list;
		this.rows = new ArrayList<Row>();
	       for (Level level : list) {
	    	   if(level.getType() == LevelSetting.unlockType){
	    		   rows.add(new LevelRow(LayoutInflater.from(context), level));
	    		   continue;
	    	   }
				switch (level.getTime()) {
				case -2:
					rows.add(new TitleNoRow(LayoutInflater.from(context), level));
					break;
				case -1:
					rows.add(new TitleRow(LayoutInflater.from(context), level));
					break;
				case 0:
					rows.add(new LevelNoRow(LayoutInflater.from(context), level));
					break;
				default:
					rows.add(new LevelRow(LayoutInflater.from(context), level));
					break;
				}
	       }
	}
	
	boolean ignoreDisabled = false;
	public boolean areAllItemsEnabled(){
		return ignoreDisabled;
	}
	public boolean isEnabled(int position){
		if(areAllItemsEnabled()){
			return true;
		}
		if(list.get(position).getTime()>0|| list.get(position).getType() == LevelSetting.unlockType){
			return true;
		}
		else{
			return false;
		}
	}
	
    @Override
    public int getViewTypeCount() {
        return RowType.values().length;
    }

    @Override
    public int getItemViewType(int position) {
        return rows.get(position).getViewType();
    }

    public int getCount() {
        return rows.size();
    }

    public Object getItem(int position) {
        return position;
    }

    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        return rows.get(position).getView(convertView, parent);
    }
}
